package com.qzxy.premiumhotelsystem.controller.admin;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qzxy.premiumhotelsystem.common.annotation.LogExecutionTime;
import com.qzxy.premiumhotelsystem.common.constant.UserRoleConstant;
import com.qzxy.premiumhotelsystem.common.enums.LogLevel;
import com.qzxy.premiumhotelsystem.common.result.Result;
import com.qzxy.premiumhotelsystem.domain.entity.Logs;
import com.qzxy.premiumhotelsystem.service.LogsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: iQNRen
 * @Description: 日志控制器
 * @Date: 2024/9/18 14:27 周三
 * @Version: 1.0
 */

//@SaCheckRole(type = UserRoleConstant.ADMIN)
@RestController
@Tag(name = "日志接口")
@RequestMapping("/logs")
public class LogsController {
    @Resource
    private LogsService logsService;

    @GetMapping("all")
    @Operation(summary = "查询所有日志")
    public Result allLogs(@RequestParam(defaultValue = "asc") String sortOrder){
        return Result.ok(logsService.allLogs(sortOrder));
    }

    @GetMapping("page")
    @Operation(summary = "分页查询日志")
    public Result pageLogs(@RequestParam @Valid Integer pageSize, @RequestParam @Valid Integer limit,@RequestParam(defaultValue = "asc") String sortOrder){
        return Result.ok(logsService.allLogsForPage(pageSize,limit,sortOrder));
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary = "删除日志")
    @LogExecutionTime(message = "删除日志",level = LogLevel.WARN)
    public Result deleteLogs(@PathVariable String id){
        return Result.ok(logsService.delByLogIdBoolean(id));
    }

    @PostMapping("update")
    @Operation(summary = "更新日志")
    @LogExecutionTime(message = "更新日志",level = LogLevel.DEBUG)
    public Result updateLogs(@RequestBody Logs logs){
            System.out.println("logs"+logs);
//        QueryWrapper<Logs> wrapper = new QueryWrapper<>();
//        wrapper.eq("log_id",logs.getLogId());
//        Logs one = logsService.getOne(wrapper);
//        one.setLogContent(logs.getLogContent());
//        one.setLogUser(logs.getLogUser());
        return Result.ok(logsService.updateIdBoolean(logs));
    }
}

